﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SAP
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
               
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ShowLoader", "Dialog.showLoader();", true);

                    MasterData masterDataWS = new MasterData();

                    //lblCompany.Text = masterDataWS.GetCompanySetting(HttpContext.Current.User.Identity.Name).Tables[0].Rows[0]["CompanyName"].ToString();
                
                    GetDefault df = new GetDefault();
                    string constr =df.GetConnection(HttpContext.Current.User.Identity.Name);
                    if (constr !="")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                          "Main.setMasterMessage('Connecting to SAP.....FAILED' " + constr + ",'');", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                          "Main.setMasterMessage('Connecting to SAP.....OK','');", true);

                        //df.CreateUDF(HttpContext.Current.User.Identity.Name);


                    }

                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading",
                                                            "Dialog.hideLoader();", true);
                }
                catch(Exception ex)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                                                           "Main.setMasterMessage('" + GeneralFunctions.UrlFullEncode(ex.ToString()) + "','');", true);

                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading",
                                                        "Dialog.hideLoader();", true);
                }
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            lblClockOut.Text = DateTime.Now.ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            lblClockIn.Text = DateTime.Now.ToString();
        }
    }
}